<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Data Driven Substructure: tensor.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Data Driven Substructure
   
   </div>
   <div id="projectbrief">A library for carrying out Multivariate Kernel Smoothing--designed to be fast and flexible for large data processing.</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">tensor.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef __TENSOR__</span>
<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define __TENSOR__</span>
<a name="l00003"></a>00003 <span class="preprocessor"></span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;valarray&gt;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00006"></a>00006 <span class="preprocessor">#include &lt;cassert&gt;</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="keyword">using namespace </span>std;
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 <span class="comment">//streamer method for valarray</span>
<a name="l00011"></a>00011 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00012"></a>00012 <span class="keyword">inline</span> ostream&amp; operator&lt;&lt;(ostream&amp; os, const valarray&lt;T&gt;&amp; v)
<a name="l00013"></a>00013 {
<a name="l00014"></a>00014   os&lt;&lt;<span class="stringliteral">&quot;Valarray: &quot;</span>;
<a name="l00015"></a>00015   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i&lt;v.size(); i++)
<a name="l00016"></a>00016     os&lt;&lt;v[i]&lt;&lt;<span class="stringliteral">&quot;,&quot;</span>;
<a name="l00017"></a>00017 
<a name="l00018"></a>00018   <span class="keywordflow">return</span> os;
<a name="l00019"></a>00019 }
<a name="l00020"></a>00020 
<a name="l00029"></a>00029 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00030"></a><a class="code" href="classTensor.html">00030</a> <span class="keyword">class </span><a class="code" href="classTensor.html" title="class for manipulating tensors">Tensor</a>
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032  <span class="keyword">public</span>:
<a name="l00033"></a>00033 
<a name="l00034"></a>00034   <a class="code" href="classTensor.html" title="class for manipulating tensors">Tensor</a>();
<a name="l00036"></a>00036   
<a name="l00037"></a>00037   <a class="code" href="classTensor.html" title="class for manipulating tensors">Tensor</a>(<span class="keywordtype">int</span> rank_, <span class="keywordtype">int</span>* length_);
<a name="l00039"></a>00039  
<a name="l00040"></a>00040   <a class="code" href="classTensor.html" title="class for manipulating tensors">Tensor</a>(<span class="keyword">const</span> valarray&lt;int&gt;&amp; length_);
<a name="l00042"></a>00042   
<a name="l00043"></a><a class="code" href="classTensor.html#a3edf1ff2c8d72b4d0c216fa37ecd83b9">00043</a>   <span class="keywordtype">int</span> Length(<span class="keywordtype">int</span> i)<span class="keyword"> const</span>
<a name="l00044"></a>00044 <span class="keyword">  </span>{
<a name="l00045"></a>00045     assert(i&gt;=0);
<a name="l00046"></a>00046     assert(i&lt;rank);
<a name="l00047"></a>00047     <span class="keywordflow">return</span> length[i];
<a name="l00048"></a>00048   }
<a name="l00050"></a>00050 
<a name="l00051"></a><a class="code" href="classTensor.html#a2ddb04a0ee784b1772452d5b6c2f4331">00051</a>   <span class="keywordtype">int</span> Rank()<span class="keyword"> const</span>
<a name="l00052"></a>00052 <span class="keyword">  </span>{<span class="keywordflow">return</span> rank;}
<a name="l00054"></a>00054 
<a name="l00055"></a>00055   T&amp; operator[](<span class="keyword">const</span> valarray&lt;int&gt;&amp; ntuple);
<a name="l00058"></a>00058 
<a name="l00059"></a>00059   T operator[](<span class="keyword">const</span> valarray&lt;int&gt;&amp; ntuple) <span class="keyword">const</span>;
<a name="l00062"></a>00062 
<a name="l00063"></a>00063   T&amp; operator[](<span class="keywordtype">int</span>);
<a name="l00066"></a>00066 
<a name="l00067"></a>00067   T operator[](<span class="keywordtype">int</span>) <span class="keyword">const</span>;
<a name="l00070"></a>00070 
<a name="l00071"></a>00071   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size() <span class="keyword">const</span>;
<a name="l00073"></a>00073 
<a name="l00074"></a>00074   valarray&lt;int&gt; IndexVec(<span class="keywordtype">int</span> index) <span class="keyword">const</span>;
<a name="l00076"></a>00076 
<a name="l00077"></a>00077   <span class="keywordtype">int</span> Index(<span class="keyword">const</span> valarray&lt;int&gt;&amp; index) <span class="keyword">const</span>;
<a name="l00079"></a>00079 
<a name="l00080"></a>00080   <span class="keywordtype">bool</span> ValidIndex(<span class="keywordtype">int</span>) <span class="keyword">const</span>;
<a name="l00082"></a>00082 
<a name="l00083"></a>00083   <span class="keywordtype">int</span> GridDistance(<span class="keywordtype">int</span> index1, <span class="keywordtype">int</span> index2) <span class="keyword">const</span>;
<a name="l00087"></a>00087 
<a name="l00088"></a>00088 
<a name="l00089"></a>00089   <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classDataSet.html" title="a class to store multi-dimensional data">DataSet</a>;
<a name="l00090"></a>00090   <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classPDF.html" title="PDF functions.">PDF</a>;
<a name="l00091"></a>00091 
<a name="l00092"></a>00092  <span class="keyword">private</span>:
<a name="l00093"></a>00093   valarray&lt;T&gt; ary;
<a name="l00095"></a>00095 
<a name="l00096"></a><a class="code" href="classTensor.html#abf6ecd9801e5de52c9e5255cbb4d1604">00096</a>   <span class="keywordtype">int</span> <a class="code" href="classTensor.html#abf6ecd9801e5de52c9e5255cbb4d1604" title="rank/dimension of tensor">rank</a>; 
<a name="l00097"></a><a class="code" href="classTensor.html#a9aef126f2198b62037f8f7d2fdc68905">00097</a>   valarray&lt;int&gt; <a class="code" href="classTensor.html#a9aef126f2198b62037f8f7d2fdc68905" title="array to store the length of each dimension">length</a>; 
<a name="l00098"></a>00098   valarray&lt;int&gt; index_helper; 
<a name="l00104"></a>00104 
<a name="l00105"></a>00105   <span class="keywordtype">void</span> initialize_index_herlper();
<a name="l00108"></a>00108 
<a name="l00109"></a>00109 };
<a name="l00110"></a>00110 
<a name="l00111"></a>00111 
<a name="l00112"></a>00112 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00113"></a><a class="code" href="classTensor.html#ae966f3807d5bfb78c049cf8c494e16ba">00113</a> <a class="code" href="classTensor.html" title="class for manipulating tensors">Tensor&lt;T&gt;::Tensor</a>() : rank(0)
<a name="l00114"></a>00114 {
<a name="l00115"></a>00115 }
<a name="l00116"></a>00116 
<a name="l00117"></a>00117 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00118"></a><a class="code" href="classTensor.html#a478b7c1715eff249a23e422fecf645fd">00118</a> <a class="code" href="classTensor.html#ae966f3807d5bfb78c049cf8c494e16ba" title="default constructor">Tensor&lt;T&gt;::Tensor</a>(<span class="keywordtype">int</span> rank_, <span class="keywordtype">int</span>* length_) : rank(rank_)
<a name="l00119"></a>00119 {
<a name="l00120"></a>00120   <span class="keywordtype">int</span> <a class="code" href="classTensor.html#a65f3440129fa379cfa7de78cede43c5d" title="return size of array">size</a>=1;
<a name="l00121"></a>00121   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i&lt;<a class="code" href="classTensor.html#abf6ecd9801e5de52c9e5255cbb4d1604" title="rank/dimension of tensor">rank</a>; i++)
<a name="l00122"></a>00122     {
<a name="l00123"></a>00123       <span class="comment">//length must be nonzero integer</span>
<a name="l00124"></a>00124       assert(length_[i]&gt;0);
<a name="l00125"></a>00125       size*=length_[i];
<a name="l00126"></a>00126     }
<a name="l00127"></a>00127 
<a name="l00128"></a>00128   <a class="code" href="classTensor.html#abd98e501acb62ff8617df796320bdefc" title="valarray to store data">ary</a>=valarray&lt;T&gt;(<a class="code" href="classTensor.html#a65f3440129fa379cfa7de78cede43c5d" title="return size of array">size</a>);
<a name="l00129"></a>00129   <a class="code" href="classTensor.html#a9aef126f2198b62037f8f7d2fdc68905" title="array to store the length of each dimension">length</a>=valarray&lt;int&gt;(length_, rank_);
<a name="l00130"></a>00130 
<a name="l00131"></a>00131   <span class="comment">//now initialize index_helper</span>
<a name="l00132"></a>00132   <a class="code" href="classTensor.html#ace6f80048f9cf60f267a371bd8480a54">initialize_index_herlper</a>();
<a name="l00133"></a>00133 }
<a name="l00134"></a>00134 
<a name="l00135"></a>00135 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00136"></a><a class="code" href="classTensor.html#a9c8059476d25909348ebbb4ed862e172">00136</a> <a class="code" href="classTensor.html#ae966f3807d5bfb78c049cf8c494e16ba" title="default constructor">Tensor&lt;T&gt;::Tensor</a>(<span class="keyword">const</span> valarray&lt;int&gt;&amp; length_) : rank(length_.size())
<a name="l00137"></a>00137 {
<a name="l00138"></a>00138   <span class="keywordtype">int</span> <a class="code" href="classTensor.html#a65f3440129fa379cfa7de78cede43c5d" title="return size of array">size</a>=1;
<a name="l00139"></a>00139   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i&lt;<a class="code" href="classTensor.html#abf6ecd9801e5de52c9e5255cbb4d1604" title="rank/dimension of tensor">rank</a>; i++)
<a name="l00140"></a>00140     {
<a name="l00141"></a>00141       <span class="comment">//length must be nonzero integer</span>
<a name="l00142"></a>00142       assert(length_[i]&gt;0);
<a name="l00143"></a>00143       size*=length_[i];
<a name="l00144"></a>00144     }
<a name="l00145"></a>00145 
<a name="l00146"></a>00146   <a class="code" href="classTensor.html#abd98e501acb62ff8617df796320bdefc" title="valarray to store data">ary</a>=valarray&lt;T&gt;(<a class="code" href="classTensor.html#a65f3440129fa379cfa7de78cede43c5d" title="return size of array">size</a>);
<a name="l00147"></a>00147   <a class="code" href="classTensor.html#a9aef126f2198b62037f8f7d2fdc68905" title="array to store the length of each dimension">length</a>=length_;
<a name="l00148"></a>00148 
<a name="l00149"></a>00149   <span class="comment">//now initialize index_helper</span>
<a name="l00150"></a>00150   <a class="code" href="classTensor.html#ace6f80048f9cf60f267a371bd8480a54">initialize_index_herlper</a>();
<a name="l00151"></a>00151                                
<a name="l00152"></a>00152 }
<a name="l00153"></a>00153 
<a name="l00154"></a>00154 
<a name="l00155"></a>00155 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00156"></a><a class="code" href="classTensor.html#acd6d6e03c121c5d084981e05d4418464">00156</a> T&amp; <a class="code" href="classTensor.html#acd6d6e03c121c5d084981e05d4418464">Tensor&lt;T&gt;::operator[]</a>(<span class="keyword">const</span> valarray&lt;int&gt;&amp; ntuple)
<a name="l00157"></a>00157 {
<a name="l00158"></a>00158   <span class="comment">//make sure index is not out of bound</span>
<a name="l00159"></a>00159   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i&lt;rank; i++)
<a name="l00160"></a>00160     assert(ntuple[i]&lt;length[i]);
<a name="l00161"></a>00161   
<a name="l00162"></a>00162   <span class="keywordflow">return</span> ary[(ntuple*index_helper).sum()];
<a name="l00163"></a>00163 }
<a name="l00164"></a>00164 
<a name="l00165"></a>00165 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00166"></a><a class="code" href="classTensor.html#a3fcfaa1fc021198496480f68c0071f6b">00166</a> T <a class="code" href="classTensor.html#acd6d6e03c121c5d084981e05d4418464">Tensor&lt;T&gt;::operator[]</a>(<span class="keyword">const</span> valarray&lt;int&gt;&amp; ntuple)<span class="keyword"> const</span>
<a name="l00167"></a>00167 <span class="keyword"></span>{
<a name="l00168"></a>00168   <span class="comment">//make sure index is not out of bound</span>
<a name="l00169"></a>00169   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i&lt;rank; i++)
<a name="l00170"></a>00170     assert(ntuple[i]&lt;length[i]);
<a name="l00171"></a>00171   
<a name="l00172"></a>00172   <span class="keywordflow">return</span> ary[(ntuple*index_helper).sum()];
<a name="l00173"></a>00173 }
<a name="l00174"></a>00174 
<a name="l00175"></a>00175 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00176"></a><a class="code" href="classTensor.html#a2c4c22e1ef1c198a7494740fb55dd148">00176</a> T&amp; <a class="code" href="classTensor.html#acd6d6e03c121c5d084981e05d4418464">Tensor&lt;T&gt;::operator[]</a>(<span class="keywordtype">int</span> index)
<a name="l00177"></a>00177 {
<a name="l00178"></a>00178   <span class="comment">//make sure index is not out of bound</span>
<a name="l00179"></a>00179   assert(ValidIndex(index));
<a name="l00180"></a>00180   
<a name="l00181"></a>00181   <span class="keywordflow">return</span> ary[index];
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183 
<a name="l00184"></a>00184 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00185"></a><a class="code" href="classTensor.html#a38a544492b07a2ec06b3c86d94ebb293">00185</a> T <a class="code" href="classTensor.html#acd6d6e03c121c5d084981e05d4418464">Tensor&lt;T&gt;::operator[]</a>(<span class="keywordtype">int</span> index)<span class="keyword"> const</span>
<a name="l00186"></a>00186 <span class="keyword"></span>{
<a name="l00187"></a>00187   <span class="comment">//make sure index is not out of bound</span>
<a name="l00188"></a>00188   assert(ValidIndex(index));
<a name="l00189"></a>00189   
<a name="l00190"></a>00190   <span class="keywordflow">return</span> ary[index];
<a name="l00191"></a>00191 }
<a name="l00192"></a>00192 
<a name="l00193"></a>00193 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00194"></a><a class="code" href="classTensor.html#a65f3440129fa379cfa7de78cede43c5d">00194</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classTensor.html#a65f3440129fa379cfa7de78cede43c5d" title="return size of array">Tensor&lt;T&gt;::size</a>()<span class="keyword"> const</span>
<a name="l00195"></a>00195 <span class="keyword"></span>{
<a name="l00196"></a>00196   <span class="keywordflow">return</span> ary.size();
<a name="l00197"></a>00197 }
<a name="l00198"></a>00198 
<a name="l00199"></a>00199 
<a name="l00200"></a>00200 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00201"></a><a class="code" href="classTensor.html#a8d360c725767f6ff5f2ac8fb5f9f4952">00201</a> valarray&lt;int&gt; <a class="code" href="classTensor.html#a8d360c725767f6ff5f2ac8fb5f9f4952" title="return a vector from an index">Tensor&lt;T&gt;::IndexVec</a>(<span class="keywordtype">int</span> index)<span class="keyword"> const</span>
<a name="l00202"></a>00202 <span class="keyword"></span>{
<a name="l00203"></a>00203   <span class="comment">//for a given index</span>
<a name="l00204"></a>00204   <span class="comment">//we want to write</span>
<a name="l00205"></a>00205   <span class="comment">//index= n1*(index_helper[0]) + n2*(index_helper[1]) + ...</span>
<a name="l00206"></a>00206   <span class="comment">//and extract the resulting vector of ni</span>
<a name="l00207"></a>00207 
<a name="l00208"></a>00208   <span class="comment">//define result</span>
<a name="l00209"></a>00209   valarray&lt;int&gt; result(rank);
<a name="l00210"></a>00210 
<a name="l00211"></a>00211   <span class="comment">//grab ni</span>
<a name="l00212"></a>00212   <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;index_helper.size(); i++)
<a name="l00213"></a>00213     {
<a name="l00214"></a>00214       <span class="comment">//extract ni</span>
<a name="l00215"></a>00215       result[i]=index/index_helper[i];
<a name="l00216"></a>00216 
<a name="l00217"></a>00217       <span class="comment">//substract away ni*index_helper[i]</span>
<a name="l00218"></a>00218       <span class="comment">//using module operator</span>
<a name="l00219"></a>00219       index%=index_helper[i];
<a name="l00220"></a>00220     }
<a name="l00221"></a>00221   <span class="keywordflow">return</span> result;
<a name="l00222"></a>00222 }
<a name="l00223"></a>00223 
<a name="l00224"></a>00224 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00225"></a><a class="code" href="classTensor.html#aafec9bc95c7876c2738c46737f032e89">00225</a> <span class="keywordtype">int</span> <a class="code" href="classTensor.html#aafec9bc95c7876c2738c46737f032e89" title="return an index from a vector">Tensor&lt;T&gt;::Index</a>(<span class="keyword">const</span> valarray&lt;int&gt;&amp; index)<span class="keyword"> const</span>
<a name="l00226"></a>00226 <span class="keyword"></span>{
<a name="l00227"></a>00227   <span class="keywordflow">return</span> (index*index_helper).sum();
<a name="l00228"></a>00228 }
<a name="l00229"></a>00229 
<a name="l00230"></a>00230 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00231"></a><a class="code" href="classTensor.html#aa88e8d6a7dd4670effc5b8ea2a424173">00231</a> <span class="keywordtype">bool</span> <a class="code" href="classTensor.html#aa88e8d6a7dd4670effc5b8ea2a424173" title="see if index is within range">Tensor&lt;T&gt;::ValidIndex</a>(<span class="keywordtype">int</span> index)<span class="keyword"> const</span>
<a name="l00232"></a>00232 <span class="keyword"></span>{
<a name="l00233"></a>00233   <span class="keywordflow">return</span> (index&gt;=0 &amp;&amp; index&lt; ary.size());
<a name="l00234"></a>00234 }
<a name="l00235"></a>00235 
<a name="l00236"></a>00236 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00237"></a><a class="code" href="classTensor.html#ac642341771abe61b6de65f11a9cf2f30">00237</a> <span class="keywordtype">int</span> <a class="code" href="classTensor.html#ac642341771abe61b6de65f11a9cf2f30">Tensor&lt;T&gt;::GridDistance</a>(<span class="keywordtype">int</span> index1, <span class="keywordtype">int</span> index2)<span class="keyword"> const</span>
<a name="l00238"></a>00238 <span class="keyword"></span>{
<a name="l00239"></a>00239   <span class="comment">//assume index1,2 are both written in the form</span>
<a name="l00240"></a>00240   <span class="comment">// n1*(index_helper[0]) + n2*(index_helper[1]) + ...</span>
<a name="l00241"></a>00241   <span class="comment">// same for</span>
<a name="l00242"></a>00242   <span class="comment">// m1*(index_helper[0]) + m2*(index_helper[1]) + ...</span>
<a name="l00243"></a>00243   <span class="comment">// we wnat to find max(ni-mi)</span>
<a name="l00244"></a>00244 
<a name="l00245"></a>00245   <span class="keywordflow">return</span> abs(IndexVec(index1)-IndexVec(index2)).max();
<a name="l00246"></a>00246 }
<a name="l00247"></a>00247 
<a name="l00248"></a>00248 <span class="keyword">template</span> &lt; <span class="keyword">typename</span> T &gt;
<a name="l00249"></a><a class="code" href="classTensor.html#ace6f80048f9cf60f267a371bd8480a54">00249</a> <span class="keywordtype">void</span> <a class="code" href="classTensor.html#ace6f80048f9cf60f267a371bd8480a54">Tensor&lt;T&gt;::initialize_index_herlper</a>()
<a name="l00250"></a>00250 {
<a name="l00251"></a>00251   <span class="comment">//the elements of index_helpers are</span>
<a name="l00252"></a>00252   <span class="comment">//[lengthn*length(n-1)*...*length1, length(n-1)*...*length1, ..., length1]</span>
<a name="l00253"></a>00253   index_helper=valarray&lt;int&gt;(rank);
<a name="l00254"></a>00254   
<a name="l00255"></a>00255   <span class="keywordtype">int</span> size=1;
<a name="l00256"></a>00256   <span class="comment">//iterate backward</span>
<a name="l00257"></a>00257   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=rank-1; i&gt;=0; --i)
<a name="l00258"></a>00258     {
<a name="l00259"></a>00259       index_helper[i]=size;
<a name="l00260"></a>00260       size*=length[i];
<a name="l00261"></a>00261     }
<a name="l00262"></a>00262 }
<a name="l00263"></a>00263 
<a name="l00264"></a>00264 
<a name="l00265"></a>00265 
<a name="l00266"></a>00266 <span class="preprocessor">#endif</span>
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Friends</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Thu Sep 12 2013 17:12:58 for Data Driven Substructure by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
